const fs = require('fs')
const express = require('express')
const path = require('path')
const server = express()
const _ = require('lodash')
const cors = require('cors')
server.use(cors())

server.get('/api/rand', (req, res) => {
    fs.readFile(path.join(__dirname, 'data/name.json'), (err, data) => {
        res.send(JSON.parse(data.toString())[_.random(0, 9)])
    })
})
server.all("*", (req, res) => {
    res.status(404)
    res.send('你要访问的资源路径不存在')
})
server.listen(3000, () => {
    console.log('web服务已启动');
})